Skip to content

Conversation

@fzhinkin
Copy link
Collaborator

Closes #448

@MohammadKHC
Copy link

Hmm @fzhinkin will this get merged soon?

@fzhinkin fzhinkin force-pushed the 448-system-line-separator branch from d878fa0 to 4a8e612 Compare December 17, 2025 15:39
@fzhinkin fzhinkin marked this pull request as ready for review December 17, 2025 16:04
@fzhinkin fzhinkin requested a review from shanshin December 17, 2025 16:05
try {
os.EOL
} catch (_: Throwable) {
"\r\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it somehow justified that we use \r\n as a fallback?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTML uses CRLF as a line separator, so I thought it's a good idea to fall back to it. But it has to be explicitly specified.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, wait, it's already documented and says that the separator is different :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JSMonk does such a choice make any sense? Or it's better to use \n?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fzhinkin Does it make sense to check whether navigator.platform is Windows, and if so, use \r\n; otherwise use \n for Android, Linux, macOS, and pretty much every other Os?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking at this from the following perspective: a browser and JS code executed inside is aimed for interaction with Internet, and the line separator used for documents shared and transferred there is somewhat unrelated to the operating system where the browser is running. That's why I picked the line separator from HTTP standard.

But IDK how far fetched it is from the actual use cases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Browsers have access to the file system now, and likely should represent the OS on which they're running.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I added window.navigator.platform-specific line separator for both Js and WasmJs

package kotlinx.io

/**
* Sequence of characters used as a line separator by the underlying platform.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to explicitly write about it in a specific platform, like:
Sequence of characters used as a line separator in Apple targets?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer having the same brief kdoc line across all actualizations, and only add platform specific details in the expanded version of a doc. But that's a personal preference, I don't have strong arguments to support it (docs will be different anyway). So we can try your suggestion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on the target, I tend to end the phrase "Sequence of characters used as a line separator ... " with:

  • "... in JS environments"
  • "... by Windows"
  • "... on Apple targets"
  • "... by Unix platforms"
  • "... by the JVM"

WDYT? The lack of consistency bugs me, and writing "on XXX targets" everywhere feels off.

Remove dependency on NodeJs modules from SystemLineSeparator.
Also, run wasmJs tests in browser, and
migrate isWindows property to NodeJs-agnostic API.
(typeof navigator !== "undefined" && navigator.platform)
|| (typeof window !== "undefined" && typeof window.navigator !== "undefined" && window.navigator.platform)
|| "unknown"
"""
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you heard a noise somewhere outside, it was most likely me screaming. :|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking both navigator and window.navigator is usually unnecessary.
In browsers, navigator is a global object and window.navigator
references the exact same object. Accessing either one yields the same value,
just like other globals attached to window.

Example to demonstrate this more clearly:

var globalVar = "I'm global!";

console.log(globalVar);        // Works
console.log(window.globalVar); // Also works and refers to the exact same variable

I would suggest only checking navigator.platform.
But it doesn't really matter ;) so yeah.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants